package com.shangma.controller;

import com.shangma.entity.User;
import com.shangma.util.AsyncFactory;
import com.shangma.util.AsyncManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * @className: TestController
 * @description:
 * @date:2021/12/22 10:32
 */
@RestController
@RequestMapping("common")
public class TestController {
    @Autowired
    private AsyncManager asyncManager;
    @GetMapping("sendCode")
    public String sendCode(){
        String phone = "";
        String code = "123456";
        asyncManager.execute(AsyncFactory.sendCode(phone,code));
        System.out.println("继续执行了");
        return "success";
    }


    @GetMapping("findByPhone/{phone}")
    public String findByPhone(@PathVariable String phone){
        System.out.println(phone);
        return "success";
    }

    @PostMapping("doLogin")
    public String doLogin(@RequestBody User user){
        System.out.println(user);
        return "success";
    }

    @PutMapping("update")
    public String update(@RequestBody User user){
        System.out.println(user);
        // 修改数据
        return "success";
    }

    @DeleteMapping("delete/{keys}")
    public String delete(@PathVariable String keys){
        System.out.println(keys);
        // 1,2,3,4
        String[] split = keys.split(",");
        List<String> strings = Arrays.asList(split);
        strings.forEach(str->{
            // 数字的字符串转换成int类型
            Integer integer = Integer.valueOf(str);
            // 根据主键删除id
            System.out.println(integer);
        });
        return "success";
    }
}
